package com.itsv.laucher.util;

import java.util.ArrayList;

import com.itsv.cyzx.bean.MainListBean;
import com.itsv.xhyy.R;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class DateAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<MainListBean> lstDate;
	private TextView txtAge;
	private TextView iv;

	// private ArrayList<Integer> ivList;

	public DateAdapter(Context mContext, ArrayList<MainListBean> list) {
		this.context = mContext;
		lstDate = list;
		// this.ivList = ivList;
		//
	}

	@Override
	public int getCount() {
		return lstDate.size();
	}

	@Override
	public Object getItem(int position) {
		return lstDate.get(position);
	}

	// public Object getItemiv(int position) {
	// return ivList.get(position);
	// }

	@Override
	public long getItemId(int position) {
		return position;
	}

	public void exchange(int startPosition, int endPosition) {

		Object endObject = getItem(endPosition);
		Object startObject = getItem(startPosition);

		lstDate.add(startPosition, (MainListBean) endObject);
		lstDate.remove(startPosition + 1);
		lstDate.add(endPosition, (MainListBean) startObject);
		lstDate.remove(endPosition + 1);
		//
		// endObject = getItemiv(endPosition);
		// startObject = getItemiv(startPosition);
		// ivList.add(startPosition, (Integer) endObject);
		// ivList.remove(startPosition + 1);
		// ivList.add(endPosition, (Integer) startObject);
		// ivList.remove(endPosition + 1);

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			if (((Activity)context).getWindowManager().getDefaultDisplay().getWidth() == 768) {
				convertView = LayoutInflater.from(context).inflate(
						R.layout.main_item_pad, null);
				
				System.out.println("-----------------------1230");
				}else{
					convertView = LayoutInflater.from(context).inflate(
							R.layout.main_item, null);
				}
		}
		txtAge = (TextView) convertView.findViewById(R.id.txt_userAge);
		iv = (TextView) convertView.findViewById(R.id.txt_new_mess);

		// iv.setVisibility(View.VISIBLE);
		// if (lstDate.get(position) == null) {
		// txtAge.setText("+");
		// txtAge.setBackgroundResource(R.drawable.red);
		// } else if (lstDate.get(position).equals("none")) {
		// txtAge.setText("");
		// txtAge.setBackgroundDrawable(null);
		// } else
		MainListBean main = lstDate.get(position);
		txtAge.setText(main.getTitle());
		txtAge.setBackgroundResource(main.getDrawable());

		if (main.getTitle().equals("知情知政") || main.getTitle().equals("政协资料")
				|| main.getTitle().equals("会议日程")) {
			RelativeLayout ll = (RelativeLayout) convertView
					.findViewById(R.id.layout_item);
			ll.setBackgroundResource(R.drawable.redbg);
		}
		/*
		 * if (main.getTitle().equals("dx")) { ImageView ib = (ImageView)
		 * convertView.findViewById(R.id.btn_qipao);
		 * ib.setVisibility(View.VISIBLE); }
		 */
		if (main.getNew_mess() > 0) {
			iv.setVisibility(View.VISIBLE);
			iv.setText(main.getNew_mess() + "");
		}
		return convertView;
	}
}
